Passed
Pull Request — master (#134)
by
unknown
02:20
created

OAuthClient.authorizeUri   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
import * as winston from "winston";
2
import * as popsicle from 'popsicle';
3
import * as jwt from 'jsonwebtoken';
4
import { AuthResponse } from "./response/AuthResponse";
5
import { Token } from "./access-token/Token";
6
import * as Csrf from 'csrf';
7
8
interface Scopes {
9
  Accounting: 'com.intuit.quickbooks.accounting',
10
  Payment: 'com.intuit.quickbooks.payment',
11
  Payroll: 'com.intuit.quickbooks.payroll',
12
  TimeTracking: 'com.intuit.quickbooks.payroll.timetracking',
13
  Benefits: 'com.intuit.quickbooks.payroll.benefits',
14
  Profile: 'profile',
15
  Email: 'email',
16
  Phone: 'phone',
17
  Address: 'address',
18
  OpenId: 'openid',
19
  Intuit_name: 'intuit_name',
20
}
21
interface Environment {
22
  sandbox: 'https://sandbox-quickbooks.api.intuit.com/',
23
  production: 'https://quickbooks.api.intuit.com/',
24
}
25
26
export default class OAuthClient {
27
  static cacheId: 'cacheID';
28
  static authorizeEndpoint: 'https://appcenter.intuit.com/connect/oauth2';
29
  static tokenEndpoint: 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer';
30
  static revokeEndpoint: 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke';
31
  static userinfo_endpoint_production:
32
    'https://accounts.platform.intuit.com/v1/openid_connect/userinfo';
33
  static userinfo_endpoint_sandbox:
34
    'https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo';
35
  static migrate_sandbox: 'https://developer-sandbox.api.intuit.com/v2/oauth2/tokens/migrate';
36
  static migrate_production: 'https://developer.api.intuit.com/v2/oauth2/tokens/migrate';
37
  static environment: Environment;
38
  static jwks_uri: 'https://oauth.platform.intuit.com/op/v1/jwks';
39
  static user_agent: string;
40
  static scopes: Scopes;
41
  environment: keyof Environment;
42
  clientId: string;
43
  clientSecret: string;
44
  redirectUri: string;
45
  token: Token;
46
  logging: boolean;
47
  logger: winston.Logger | null;
48
  state: Csrf;
49
50
  constructor(params: {
51
    clientId: string,
52
    clientSecret: string,
53
    environment: keyof Environment,
54
    redirectUri: string
55
  });
56
  getJson(): Record<string, any>;
57
  setToken(opts: {
58
    access_token: string;
59
    refresh_token: string;
60
    token_type: string;
61
    expires_in: number;
62
    x_refresh_token_expires_in: number;
63
    id_token?: string;
64
    createdAt?: number
65
  }): Token;
66
  setAuthorizeURLs(params: {
67
    authorizeEndpoint: string;
68
    tokenEndpoint: string;
69
    revokeEndpoint: string;
70
    userInfoEndpoint: string;
71
  }): this;
72
  authorizeUri(opts: {
73
    scope: Scopes[keyof Scopes][],
74
    state: string
75
  }): string;
76
  createToken(uri: string): Promise<AuthResponse>;
77
  refresh(): Promise<AuthResponse>;
78
  refreshUsingToken(refreshToken: string): Promise<AuthResponse>;
79
  revoke(params?: { access_token: string, refresh_token: string }): Promise<AuthResponse>;
80
  getUserInfo(): Promise<AuthResponse>;
81
  makeApiCall(params: { transport: popsicle.TransportOptions, url: string, method: string, headers: Record<string, string>, body: Record<string, any> }): Promise<AuthResponse>;
82
  validateIdToken(params?: { id_token: string }): Promise<AuthResponse>;
83
  getKeyFromJWKsURI(id_token: string, kid: string, request: popsicle.Request): Promise<ReturnType<typeof jwt.verify>>;
84
  getPublicKey(): string;
85
  getTokenRequest(request: popsicle.Request): Promise<AuthResponse>;
86
  validateToken(): boolean;
87
  loadResponse(request: popsicle.Request): Promise<popsicle.Response>;
88
  loadResponseFromJWKsURI(request: popsicle.Request): Promise<popsicle.Response>;
89
  createError(e: Error, authResponse: AuthResponse): Error;
90
  isAccessTokenValid(): boolean;
91
  getToken(): Token;
92
  authHeader(): string;
93
  log(level: keyof winston.config.NpmConfigSetLevels, message: string, messageData: string): void;
94
}
95